function vector=weight(wgrid,y,prob)

vector=zeros(1,length(wgrid));

if y<max(wgrid) && y>=min(wgrid)
pos_grid=sum(wgrid<=y);    
alpha=(y-wgrid(pos_grid+1))/(wgrid(pos_grid)-wgrid(pos_grid+1)); %alpha*wgrid(pos_grid)+(1-alpha)*wgrid(pos_grid+1)=y
vector(1,pos_grid)=alpha*prob;
vector(1,pos_grid+1)=(1-alpha)*prob;
 

elseif y>=max(wgrid)    
vector(1,length(wgrid))=prob;


else %y<min(wgrid)
vector(1,1)=prob;

end    
    
    